package cm.tl.pms.util;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;

/**
 * @author w7h1te_ywq
 * @version 1.0.0
 * @date 2024-01-09 13:38
 */
public class SMSUtil {
    // 短信应用SDK AppID  1400开头
    private static final int APPID = 1400569482;
    // 短信应用SDK AppKey
    private static final String APPKEY = "89dbcd46d747b618ea4c44cc9fb30efd";

    public static void main(String[] args) {
        SMSUtil.sendSMS("15893840002", "123456");
    }

    /**
     * 发送验证码
     *
     * @param phoneNumber
     * @return
     */
    public static boolean sendSMS(String phoneNumber, String code) {
        try {
            //参数，一定要对应短信模板中的参数顺序和个数，
            String[] params = {code};
            //创建ssender对象
            SmsSingleSender ssender = new SmsSingleSender(APPID, APPKEY);
            //发送
            SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumber, 1120232, params, "天成通链", "", "");
            if (result.result != 0) {
                return false;
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

}